package com.xmqian.app.project.ui.preview.activity

import android.R
import android.content.Context
import android.content.Intent
import android.view.View
import android.view.ViewGroup
import androidx.activity.enableEdgeToEdge
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.coszero.ui.recycler.RecyclerDiverUtils
import com.coszero.utils.base.BaseRecyclerAdapter
import com.coszero.utils.base.BaseRecyclerViewHolder
import com.coszero.utils.utils.ResourceUtils
import com.example.xmqian.databinding.ActivityPagePreviewBinding
import com.xmqian.app.project.common.base.BaseMyActivity

internal class PagePreviewActivity : BaseMyActivity() {
    private var binding: ActivityPagePreviewBinding? = null


    override fun getLayoutView(): View {
        binding = ActivityPagePreviewBinding.inflate(layoutInflater)
        this.enableEdgeToEdge()
        ViewCompat.setOnApplyWindowInsetsListener(
            binding!!.root
        ) { v: View, insets: WindowInsetsCompat ->
            val systemBars =
                insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        return binding!!.root
    }

    override fun initView() {
        val list: MutableList<String> = ArrayList()
        list.add("预览界面1")
        list.add("预览界面2")
        list.add("预览界面3")
        list.add("预览界面4")
        list.add("预览界面5")
        binding!!.rvContent.layoutManager = LinearLayoutManager(mActivity)
        binding!!.rvContent.addItemDecoration(RecyclerDiverUtils.hDiver(mActivity))
        val baseRecyclerAdapter: BaseRecyclerAdapter<*> =
            object : BaseRecyclerAdapter<BaseRecyclerViewHolder?>(
                this, list
            ) {
                override fun onCreateViewHolder(
                    parent: ViewGroup,
                    viewType: Int
                ): BaseRecyclerViewHolder {
                    return BaseRecyclerViewHolder(
                        mActivity,
                        View.inflate(mActivity, R.layout.simple_list_item_1, null)
                    )
                }

                override fun onBindViewHolder(holder: BaseRecyclerViewHolder, position: Int) {
                    holder.getTextView(R.id.text1).text =
                        list[position]
                    holder.getTextView(R.id.text1).setTextColor(
                        ResourceUtils.getColor(
                            mContext,
                            com.example.xmqian.R.color.black
                        )
                    )
                }

                override fun getItemCount(): Int {
                    return list.size
                }
            }
        binding!!.rvContent.adapter = baseRecyclerAdapter
    }

    override fun initData() {
    }

    companion object {
        fun startActivity(context: Context) {
            val intent = Intent()
            intent.setClass(context, PagePreviewActivity::class.java)
            context.startActivity(intent)
        }
    }
}